package com.jnu.assistant.mapper;

import com.jnu.assistant.pojo.Conversation;
import com.jnu.assistant.pojo.UserSessionId;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ChatMapper {

    @Insert("insert into session(userId, title) values(#{userId},#{title})")
    @Options(useGeneratedKeys = true, keyProperty = "sessionId", keyColumn = "sessionId")
    void addSession(UserSessionId userSessionId);

    @Select("select * from session where userId=#{userId}")
    List<UserSessionId> getSession(int userId);

    @Delete("delete from session where sessionId=#{sessionId}")
    void deleteSession(int sessionId);

    @Insert("insert into conversation(sessionId, userMessage, serverMessage) VALUES(#{sessionId},#{userMessage},#{serverMessage}) ")
    void addConversation(Conversation conversation);

    @Select("select * from conversation where sessionId=#{sessionId}")
    List<Conversation> getConversations(int sessionId);

    @Delete("delete from conversation where sessionId=#{sessionId}")
    void deleteConversations(int sessionId);
}
